package main

import (
	"fmt"
	"time"
	"github.com/seafooler/dumbo/config"
	"github.com/seafooler/dumbo/core"
)

func main() {
	// Create configuration for a single node
	conf := &config.Config{
		Id:           0,
		N:            4,
		F:            1,
		MaxPayloadSize: 5000,
		LogLevel:     1, // INFO level
		MockLatency:  0, // No artificial latency
	}

	// Create node
	node := core.NewNode(conf)
	
	fmt.Printf("Starting Dumbo node with 250-byte transactions\n")
	fmt.Printf("Node ID: %d, N: %d, F: %d\n", conf.Id, conf.N, conf.F)
	
	// Start consensus
	node.StartConsensus()
	
	// Run for 30 seconds
	time.Sleep(30 * time.Second)
	
	// Get final statistics
	stats := node.GetStats()
	
	fmt.Printf("\n=== Final Performance Statistics ===\n")
	fmt.Printf("Total TPS: %.2f\n", stats["tps"])
	fmt.Printf("Total Transactions: %d\n", stats["processed_txs"])
	fmt.Printf("Consensus Rounds: %d\n", stats["consensus_rounds"])
	fmt.Printf("Uptime: %.2f seconds\n", stats["uptime_seconds"])
	
	// Performance logger metrics
	if stats["perf_total_tps"] != nil {
		fmt.Printf("\n=== Performance Logger Metrics ===\n")
		fmt.Printf("Performance TPS: %.2f\n", stats["perf_total_tps"])
		fmt.Printf("Total Size: %d bytes\n", stats["perf_total_size"])
		fmt.Printf("Average Epoch TPS: %.2f\n", stats["perf_avg_epoch_tps"])
		fmt.Printf("Average Epoch Latency: %.3f seconds\n", stats["perf_avg_epoch_latency"])
		fmt.Printf("Component Delays (ms):\n")
		fmt.Printf("  RBC: %.2f\n", stats["perf_rbc_delay"])
		fmt.Printf("  ABA: %.2f\n", stats["perf_aba_delay"])
		fmt.Printf("  MVBA: %.2f\n", stats["perf_mvba_delay"])
		fmt.Printf("  ACS: %.2f\n", stats["perf_acs_delay"])
	}
	
	// Close node and log summary
	node.Close()
	
	fmt.Printf("\nTest completed. Check logs/ directory for detailed CSV logs.\n")
}
